
<?php
	header("Content-type:text/html;charset=utf-8");
	// require 'ConnDB.php';
	// require 'config.php';
	require_once(dirname(__FILE__).'/'."../../basic/Model.php");
	class StaffModel extends Model{
		//private $conn;

		function __construct(){
			parent::__construct();
		}
		
		function staff_account($id){
			$sql = "select * from employees where id={$id}";
			$row=$this->conn->query($sql);	
			return $row;
		}	

		function staff_edit($id){
			$sql = "select * from employees where id={$id}";
			$row=$this->conn->query($sql);	
			return $row;
		}

		function staff_update($data){
			$id = $_POST['id'];
  			$staff = array(
  				'id'=>$id,
				'name' => trim($_POST['name']),
 				'pass'=>$_POST['pass'],
				'sex' => $_POST['sex'],
				'Birth' => $_POST['Birth'],
				'home' => $_POST['home'],
				'idcard' => $_POST['idcard'],
  			);
			//$result=$this->conn->query($sql);
			$result =$this->conn->update('employees',$staff,'id='.$id);
			return $result;
		}

		function Dostaff_apply(){
			$time=time();
			$times=date('y-m-d h:i:s',time());
			$id = $_POST['id'];
  			$staff = array(
  				'id'=>$id,
				'name' => trim($_POST['name']),
				'type'=>$_POST['type'],
				'content'=>$_POST['content'],
				'wtime'=>$times
  			);
  			$sql2="select * from works where id='".$id."'";
  			 $jud=$this->conn->query($sql2);
  	
  			 if(!$jud){
  			 	$keys=implode(',', array_keys($staff));
			$values=implode("','",array_values($staff));
			$sql="insert into works ({$keys})values('{$values}')";
			$result=$this->conn->query($sql);
			return $result;
  			 }
  			 else{

  			 	return $jud;  			 }
			//$result=$this->conn->query($sql);
			
		}
	}
?>